package com.whh.tq.common;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import android.os.Handler;

public class AsyncLoader {
	private static final ExecutorService executorService = Executors.newFixedThreadPool(5);
	private static final Handler handler = new Handler();

	/**
	 * 异步加载
	 * @param load
	 * @param callback
	 */
	public static void execute(final Execute execute, final Callback callback) {
		executorService.submit(new Runnable() {
			public void run() {
				final Object obj = execute.execute();
				handler.post(new Runnable() {
					public void run() {
						callback.callback(obj);
					}
				});
			}
		});
	}

	/**
	 * 异步加载回调接口
	 *
	 */
	public interface Callback {
		public void callback(Object obj);
	}

	/**
	 * 异步加载执行接口
	 *
	 */
	public interface Execute {
		public Object execute();
	}
}
